package cc.imos.component.activemq;

import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.command.ActiveMQQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.jms.Queue;
import java.text.DateFormat;
import java.util.Date;

/**
 * 消息生产类 <br />
 *
 * Created by asher on 2017/3/23.
 */
@Slf4j
//@Component
public class ProducerComponent {

//    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private Queue queue;

//    @Scheduled(fixedDelay = 60 * 1000)//每60s执行1次
    public void send() {
        String message = ">>>>>>>>> " + DateFormat.getDateTimeInstance().format(new Date());
        this.jmsMessagingTemplate.convertAndSend(this.queue, message);
    }



    @Bean
    public Queue queue() {
        return new ActiveMQQueue("sample.queue");
    }

}